/**
 * 
 */
package pizza.admin.entity;

import static javax.persistence.GenerationType.IDENTITY;

import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.Type;

import pizza.admin.helper.FormatterHelper;
import pizza.admin.helper.HtmlHelper;

/**
 * @author Joro
 * @version 1.0
 */

@Entity
@Table(name = "OrderPizza")
public class OrderPizza {
	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "id", unique = true, nullable = true)
	private Integer id;

//	, columnDefinition = “int default 100")
	@Column(name = "count", unique = false, nullable = false)
	private Integer count;

	@ManyToOne
	@JoinColumn(name = "pizzaId")
	private Pizza pizza;

	@ManyToOne
	@JoinColumn(name = "orderId")
	private Order order;

	public OrderPizza() {
		super();
		id = null;
		count = 1;
		pizza = new Pizza();
		order = new Order();
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Integer getCount() {
		return count;
	}

	public void setCount(Integer count) {
		this.count = count;
	}

	public Pizza getPizza() {
		return pizza;
	}

	public void setPizza(Pizza pizza) {
		this.pizza = pizza;
	}

	public Order getOrder() {
		return order;
	}

	public void setOrder(Order order) {
		this.order = order;
	}
	
	public Double calculateFullPrice(){
		FormatterHelper formatter = new FormatterHelper();
		double fullPrice = this.getPizza().getPrice()*this.getCount();
		return formatter.roundTwoDecimals(fullPrice);
	}
	
	public Boolean validateForDB() {

		// validate before add
		if (count < 1 || pizza.getId() == null || order.getId() == null) {
			return false;
		}
		return true;

	}

	public void purifyFields() {
		HtmlHelper helper = new HtmlHelper();

	}

}
